<?php
/**
 * Copyright © 2013-2017 Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

?>
<?php $_giftMessage = false; ?>
<?php switch ($block->getCheckoutType()): ?>
<?php case 'onepage_checkout': ?>
    <fieldset class="fieldset gift-message">
        <legend class="legend"><span><?php /* @escapeNotVerified */ echo __('Do you have any gift items in your order?'); ?></span></legend><br>

        <div class="field choice" id="add-gift-options-<?php /* @escapeNotVerified */ echo $block->getEntity()->getId() ?>">
            <input type="checkbox" name="allow_gift_options" id="allow_gift_options" data-mage-init='{"giftOptions":{}}' value="1" data-selector='{"id":"#allow-gift-options-container"}'<?php if ($block->getItemsHasMesssages() || $block->getEntityHasMessage()): ?> checked="checked"<?php endif; ?> class="checkbox" />
            <label for="allow_gift_options" class="label"><span><?php /* @escapeNotVerified */ echo __('Add gift options') ?></span></label>
        </div>

        <dl class="options-items" id="allow-gift-options-container">
            <?php if ($block->isMessagesAvailable()): ?>
            <dt id="add-gift-options-for-order-<?php /* @escapeNotVerified */ echo $block->getEntity()->getId() ?>" class="order-title">
                <div class="field choice">
                    <input type="checkbox" name="allow_gift_messages_for_order" id="allow_gift_options_for_order" data-mage-init='{"giftOptions":{}}' value="1" data-selector='{"id":"#allow-gift-options-for-order-container"}'<?php if ($block->getEntityHasMessage()): ?> checked="checked"<?php endif; ?> class="checkbox" />
                    <label for="allow_gift_options_for_order" class="label"><span><?php /* @escapeNotVerified */ echo __('Gift Options for the Entire Order'); ?></span></label>
                </div>
            </dt>

            <dd id="allow-gift-options-for-order-container" class="order-options">
                <div class="options-order-container" id="options-order-container-<?php /* @escapeNotVerified */ echo $block->getEntity()->getId() ?>"></div>
                    <a href="#" class="action activate message" data-mage-init='{"toggleAdvanced": {"selectorsToggleClass":"hidden", "toggleContainers":"#allow-gift-messages-for-order-container"}}'><?php /* @escapeNotVerified */ echo __('Gift Message') ?></a>
                    <div id="allow-gift-messages-for-order-container" class="gift-messages-order hidden">
                        <fieldset class="fieldset">
                            <p><?php /* @escapeNotVerified */ echo __('Leave this box blank if you don\'t want to leave a gift message for the entire order.') ?></p>
                            <div class="field from">
                                <label for="gift-message-whole-from" class="label"><span><?php /* @escapeNotVerified */ echo __('From') ?></span></label>
                                <div class="control">
                                    <input type="text" name="giftmessage[quote][<?php /* @escapeNotVerified */ echo $block->getEntity()->getId() ?>][from]" id="gift-message-whole-from" title="<?php /* @escapeNotVerified */ echo __('From') ?>"  value="<?php /* @escapeNotVerified */ echo $block->getEscaped($block->getMessage()->getSender(), $block->getDefaultFrom()) ?>" class="input-text">
                                </div>
                            </div>
                            <div class="field to">
                                <label for="gift-message-whole-to" class="label"><span><?php /* @escapeNotVerified */ echo __('To') ?></span></label>
                                <div class="control">
                                    <input type="text" name="giftmessage[quote][<?php /* @escapeNotVerified */ echo $block->getEntity()->getId() ?>][to]" id="gift-message-whole-to" title="<?php /* @escapeNotVerified */ echo __('To') ?>" value="<?php /* @escapeNotVerified */ echo $block->getEscaped($block->getMessage()->getRecipient(), $block->getDefaultTo()) ?>" class="input-text">
                                </div>
                            </div>
                            <div class="field text">
                                <label for="gift-message-whole-message" class="label"><span><?php /* @escapeNotVerified */ echo __('Message') ?></span></label>
                                <div class="control">
                                    <textarea id="gift-message-whole-message" class="input-text" name="giftmessage[quote][<?php /* @escapeNotVerified */ echo $block->getEntity()->getId() ?>][message]" title="<?php /* @escapeNotVerified */ echo __('Message') ?>" rows="5" cols="10"><?php /* @escapeNotVerified */ echo $block->getEscaped($block->getMessage()->getMessage()) ?></textarea>
                                </div>
                            </div>
                        </fieldset>
                        <script>
require(['jquery'], function(jQuery){

    jQuery('#add-gift-options-<?php /* @escapeNotVerified */ echo $block->getEntity()->getId() ?>')
        .add('#add-gift-options-for-order-<?php /* @escapeNotVerified */ echo $block->getEntity()->getId() ?>').removeClass('hidden');

});
</script>
                    </div>
            </dd>
            <?php endif ?>
            <?php if ($block->isItemsAvailable()): ?>
            <dt id="add-gift-options-for-items-<?php /* @escapeNotVerified */ echo $block->getEntity()->getId() ?>" class="order-title individual">
                <div class="field choice">
                    <input type="checkbox" name="allow_gift_options_for_items" id="allow_gift_options_for_items" data-mage-init='{"giftOptions":{}}' value="1" data-selector='{"id":"#allow-gift-options-for-items-container"}'<?php if ($block->getItemsHasMesssages()): ?> checked="checked"<?php endif; ?> class="checkbox" />
                    <label for="allow_gift_options_for_items" class="label"><span><?php /* @escapeNotVerified */ echo __('Gift Options for Individual Items'); ?></span></label>
                </div>
            </dt>

            <dd id="allow-gift-options-for-items-container" class="order-options individual">
                <ol class="items">
                    <?php foreach ($block->getItems() as $_index => $_item): ?>
                    <?php $_product = $_item->getProduct() ?>
                    <li class="item">
                         <div class="product">
                             <div class="number">
                                 <?php /* @escapeNotVerified */ echo __('<span>Item %1</span> of %2', $_index+1, $block->countItems()) ?>
                             </div>
                             <div class="img photo container">
                                 <?php echo $block->getImage($_product, 'gift_messages_checkout_thumbnail')->toHtml(); ?>
                             </div>
                             <strong class="product name"><?php echo $block->escapeHtml($_product->getName()) ?></strong>
                         </div>
                         <div class="options">
                             <div class="options-items-container" id="options-items-container-<?php /* @escapeNotVerified */ echo $block->getEntity()->getId() ?>-<?php /* @escapeNotVerified */ echo $_item->getId() ?>"></div>
                             <?php if ($block->isItemMessagesAvailable($_item)): ?>
                             <a href="#" class="action activate message" data-mage-init='{"toggleAdvanced": {"selectorsToggleClass":"hidden", "toggleContainers":"#gift-messages-for-item-container-<?php /* @escapeNotVerified */ echo $_item->getId() ?>"}}'><?php /* @escapeNotVerified */ echo __('Gift Message') ?></a>
                             <div id="gift-messages-for-item-container-<?php /* @escapeNotVerified */ echo $_item->getId() ?>" class="block message hidden">
                                 <fieldset class="fieldset">
                                     <p><?php /* @escapeNotVerified */ echo __('Leave a box blank if you don\'t want to add a gift message for that item.') ?></p>
                                     <div class="field from">
                                         <label for="gift-message-<?php /* @escapeNotVerified */ echo $_item->getId() ?>-from" class="label"><span><?php /* @escapeNotVerified */ echo __('From') ?></span></label>
                                         <div class="control">
                                             <input type="text" name="giftmessage[quote_item][<?php /* @escapeNotVerified */ echo $_item->getId() ?>][from]" id="gift-message-<?php /* @escapeNotVerified */ echo $_item->getId() ?>-from" title="<?php /* @escapeNotVerified */ echo __('From') ?>" value="<?php /* @escapeNotVerified */ echo $block->getEscaped($block->getMessage($_item)->getSender(), $block->getDefaultFrom()) ?>" class="input-text">
                                         </div>
                                     </div>
                                     <div class="field to">
                                        <label for="gift-message-<?php /* @escapeNotVerified */ echo $_item->getId() ?>-to" class="label"><span><?php /* @escapeNotVerified */ echo __('To') ?></span></label>
                                        <div class="control">
                                            <input type="text" name="giftmessage[quote_item][<?php /* @escapeNotVerified */ echo $_item->getId() ?>][to]" id="gift-message-<?php /* @escapeNotVerified */ echo $_item->getId() ?>-to" title="<?php /* @escapeNotVerified */ echo __('To') ?>" value="<?php /* @escapeNotVerified */ echo $block->getEscaped($block->getMessage($_item)->getRecipient(), $block->getDefaultTo()) ?>" class="input-text">
                                        </div>
                                     </div>
                                     <div class="field text">
                                         <label for="gift-message-<?php /* @escapeNotVerified */ echo $_item->getId() ?>-message" class="label"><span><?php /* @escapeNotVerified */ echo __('Message') ?></span></label>
                                         <div class="control">
                                            <textarea id="gift-message-<?php /* @escapeNotVerified */ echo $_item->getId() ?>-message" class="input-text giftmessage-area" name="giftmessage[quote_item][<?php /* @escapeNotVerified */ echo $_item->getId() ?>][message]" title="<?php /* @escapeNotVerified */ echo __('Message') ?>" rows="5" cols="40"><?php /* @escapeNotVerified */ echo $block->getEscaped($block->getMessage($_item)->getMessage()) ?></textarea>
                                         </div>
                                     </div>
                                </fieldset>
                             </div>
                         <?php endif; ?>
                         </div>
                    </li>
                    <?php endforeach; ?>
                </ol>
            </dd>
            <script>
require(['jquery'], function(jQuery){

    jQuery('#add-gift-options-<?php /* @escapeNotVerified */ echo $block->getEntity()->getId() ?>')
        .add('#add-gift-options-for-items-<?php /* @escapeNotVerified */ echo $block->getEntity()->getId() ?>').removeClass('hidden');

});
</script>
            <?php endif; ?>
            <dt class="extra-options-container" id="extra-options-container-<?php /* @escapeNotVerified */ echo $block->getEntity()->getId() ?>"></dt>
        </dl>
    </fieldset>
<script type="text/x-magento-init">
{
    "#allow_gift_options, #allow_gift_options_for_order, #allow_gift_options_for_items": {
        "giftOptions": {}
    }
}
</script>
<?php break; ?>

<?php case 'multishipping_address': ?>
    <fieldset id="add-gift-options-<?php /* @escapeNotVerified */ echo $block->getEntity()->getId() ?>" class="fieldset gift-message">
        <legend class="legend"><span><?php /* @escapeNotVerified */ echo __('Do you have any gift items in your order?'); ?></span></legend><br>

        <div class="field choice" id="add-gift-options-<?php /* @escapeNotVerified */ echo $block->getEntity()->getId() ?>">
            <input type="checkbox" name="allow_gift_options_<?php /* @escapeNotVerified */ echo $block->getEntity()->getId() ?>" id="allow_gift_options_<?php /* @escapeNotVerified */ echo $block->getEntity()->getId() ?>" data-mage-init='{"giftOptions":{}}' value="1" data-selector='{"id":"#allow-gift-options-container-<?php /* @escapeNotVerified */ echo $block->getEntity()->getId() ?>"}'<?php if ($block->getItemsHasMesssages() || $block->getEntityHasMessage()): ?> checked="checked"<?php endif; ?> class="checkbox" />
            <label for="allow_gift_options_<?php /* @escapeNotVerified */ echo $block->getEntity()->getId() ?>" class="label"><span><?php /* @escapeNotVerified */ echo __('Add gift options') ?></span></label>
        </div>

        <dl class="options-items" id="allow-gift-options-container-<?php /* @escapeNotVerified */ echo $block->getEntity()->getId() ?>">
            <dt id="add-gift-options-for-order-<?php /* @escapeNotVerified */ echo $block->getEntity()->getId() ?>" class="order-title">
                <div class="field choice">
                    <input type="checkbox" name="allow_gift_options_for_order_<?php /* @escapeNotVerified */ echo $block->getEntity()->getId() ?>" id="allow_gift_options_for_order_<?php /* @escapeNotVerified */ echo $block->getEntity()->getId() ?>" data-mage-init='{"giftOptions":{}}' value="1" data-selector='{"id":"#allow-gift-options-for-order-container-<?php /* @escapeNotVerified */ echo $block->getEntity()->getId() ?>"}'<?php if ($block->getEntityHasMessage()): ?> checked="checked"<?php endif; ?> class="checkbox" />
                    <label for="allow_gift_options_for_order_<?php /* @escapeNotVerified */ echo $block->getEntity()->getId() ?>" class="label"><span><?php /* @escapeNotVerified */ echo __('Add Gift Options for the Entire Order') ?></span></label>
                </div>
            </dt>

            <dd id="allow-gift-options-for-order-container-<?php /* @escapeNotVerified */ echo $block->getEntity()->getId() ?>" class="order-options">
                <div class="options-order-container" id="options-order-container-<?php /* @escapeNotVerified */ echo $block->getEntity()->getId() ?>"></div>
                <?php if ($block->isMessagesAvailable()): ?>
                    <?php $_giftMessage = true; ?>
                    <a href="#" class="action activate message" data-mage-init='{"toggleAdvanced": {"selectorsToggleClass":"hidden", "toggleContainers":"#gift-messages-for-order-container-<?php /* @escapeNotVerified */ echo $block->getEntity()->getId() ?>"}}'><?php /* @escapeNotVerified */ echo __('Gift Message') ?></a>
                    <div id="gift-messages-for-order-container-<?php /* @escapeNotVerified */ echo $block->getEntity()->getId() ?>" class="gift-messages-order hidden">
                        <fieldset class="fieldset">
                            <p><?php /* @escapeNotVerified */ echo __('You can leave this box blank if you don\'t want to add a gift message for this address.') ?></p>
                            <div class="field from">
                                <label for="gift-message-<?php /* @escapeNotVerified */ echo $block->getEntity()->getId() ?>-from" class="label"><span><?php /* @escapeNotVerified */ echo __('From') ?></span></label>
                                <div class="control">
                                    <input type="text" name="giftmessage[quote_address][<?php /* @escapeNotVerified */ echo $block->getEntity()->getId() ?>][from]" id="gift-message-<?php /* @escapeNotVerified */ echo $block->getEntity()->getId() ?>-from" title="<?php /* @escapeNotVerified */ echo __('From') ?>" value="<?php /* @escapeNotVerified */ echo $block->getEscaped($block->getMessage()->getSender(), $block->getDefaultFrom()) ?>" class="input-text">
                                </div>
                            </div>
                            <div class="field to">
                                <label for="gift-message-<?php /* @escapeNotVerified */ echo $block->getEntity()->getId() ?>-to" class="label"><span><?php /* @escapeNotVerified */ echo __('To') ?></span></label>
                                <div class="control">
                                    <input type="text" name="giftmessage[quote_address][<?php /* @escapeNotVerified */ echo $block->getEntity()->getId() ?>][to]" id="gift-message-<?php /* @escapeNotVerified */ echo $block->getEntity()->getId() ?>-to" title="<?php /* @escapeNotVerified */ echo __('To') ?>" value="<?php /* @escapeNotVerified */ echo $block->getEscaped($block->getMessage()->getRecipient(), $block->getDefaultTo()) ?>" class="input-text">
                                </div>
                            </div>
                            <div class="field text">
                                <label for="gift-message-<?php /* @escapeNotVerified */ echo $block->getEntity()->getId() ?>-message" class="label"><span><?php /* @escapeNotVerified */ echo __('Message') ?></span></label>
                                <div class="control">
                                    <textarea id="gift-message-<?php /* @escapeNotVerified */ echo $block->getEntity()->getId() ?>-message" class="input-text" name="giftmessage[quote_address][<?php /* @escapeNotVerified */ echo $block->getEntity()->getId() ?>][message]" title="<?php /* @escapeNotVerified */ echo __('Message') ?>" rows="5" cols="40"><?php /* @escapeNotVerified */ echo $block->getEscaped($block->getMessage()->getMessage()) ?></textarea>
                                </div>
                            </div>
                        </fieldset>
                    </div>
                 <?php endif; ?>
            </dd>

            <?php if ($block->isItemsAvailable()): ?>
            <dt id="add-gift-options-for-items-<?php /* @escapeNotVerified */ echo $block->getEntity()->getId() ?>" class="order-title individual">
                <div class="field choice">
                    <input type="checkbox" name="allow_gift_options_for_items_<?php /* @escapeNotVerified */ echo $block->getEntity()->getId() ?>" id="allow_gift_options_for_items_<?php /* @escapeNotVerified */ echo $block->getEntity()->getId() ?>" data-mage-init='{"giftOptions":{}}' value="1" data-selector='{"id":"#allow-gift-options-for-items-container-<?php /* @escapeNotVerified */ echo $block->getEntity()->getId() ?>"}'<?php if ($block->getItemsHasMesssages()): ?> checked="checked"<?php endif; ?> class="checkbox" />
                    <label for="allow_gift_options_for_items_<?php /* @escapeNotVerified */ echo $block->getEntity()->getId() ?>" class="label"><span><?php /* @escapeNotVerified */ echo __('Add gift options for Individual Items') ?></span></label>
                </div>
            </dt>

            <dd id="allow-gift-options-for-items-container-<?php /* @escapeNotVerified */ echo $block->getEntity()->getId() ?>" class="order-options individual">
                 <ol class="items">
                 <?php foreach ($block->getItems() as $_index => $_item): ?>
                 <?php $_product = $_item->getProduct() ?>
                     <li class="item">
                         <div class="product">
                             <div class="number"><?php /* @escapeNotVerified */ echo __('<span>Item %1</span> of %2', $_index+1, $block->countItems()) ?></div>
                             <div class="img photo container">
                                 <?php echo $block->getImage($_product, 'gift_messages_checkout_thumbnail')->toHtml(); ?>
                             </div>
                             <strong class="product-name"><?php echo $block->escapeHtml($_product->getName()) ?></strong>
                         </div>
                         <div class="options">
                             <div class="options-items-container" id="options-items-container-<?php /* @escapeNotVerified */ echo $block->getEntity()->getId() ?>-<?php /* @escapeNotVerified */ echo $_item->getId() ?>"></div>
                             <input type="hidden" name="giftoptions[quote_address_item][<?php /* @escapeNotVerified */ echo $_item->getId() ?>][address]" value="<?php /* @escapeNotVerified */ echo $block->getEntity()->getId()?>" />

                             <?php if ($block->isItemMessagesAvailable($_item)): ?>
                             <?php $_giftMessage = true; ?>
                                 <a href="#" class="action activate message" data-mage-init='{"toggleAdvanced": {"selectorsToggleClass":"hidden", "toggleContainers":"#gift-messages-for-item-container-<?php /* @escapeNotVerified */ echo $_item->getId() ?>"}}'><?php /* @escapeNotVerified */ echo __('Gift Message') ?></a>
                                 <div id="gift-messages-for-item-container-<?php /* @escapeNotVerified */ echo $_item->getId() ?>" class="block message hidden">
                                     <fieldset class="fieldset">
                                        <p><?php /* @escapeNotVerified */ echo __('You can leave this box blank if you don\'t want to add a gift message for the item.') ?></p>
                                         <input type="hidden" name="giftmessage[quote_address_item][<?php /* @escapeNotVerified */ echo $_item->getId() ?>][address]" value="<?php /* @escapeNotVerified */ echo $block->getEntity()->getId()?>" />
                                         <div class="field from">
                                             <label for="gift-message-<?php /* @escapeNotVerified */ echo $_item->getId() ?>-from" class="label"><span><?php /* @escapeNotVerified */ echo __('From') ?></span></label>
                                             <div class="control">
                                                 <input type="text" name="giftmessage[quote_address_item][<?php /* @escapeNotVerified */ echo $_item->getId() ?>][from]" id="gift-message-<?php /* @escapeNotVerified */ echo $_item->getId() ?>-from" title="<?php /* @escapeNotVerified */ echo __('From') ?>"  value="<?php /* @escapeNotVerified */ echo $block->getEscaped($block->getMessage($_item)->getSender(), $block->getDefaultFrom()) ?>" class="input-text">
                                             </div>
                                         </div>
                                         <div class="field to">
                                            <label for="gift-message-<?php /* @escapeNotVerified */ echo $_item->getId() ?>-to" class="label"><span><?php /* @escapeNotVerified */ echo __('To') ?></span></label>
                                            <div class="control">
                                                <input type="text" name="giftmessage[quote_address_item][<?php /* @escapeNotVerified */ echo $_item->getId() ?>][to]" id="gift-message-<?php /* @escapeNotVerified */ echo $_item->getId() ?>-to" title="<?php /* @escapeNotVerified */ echo __('To') ?>" value="<?php /* @escapeNotVerified */ echo $block->getEscaped($block->getMessage($_item)->getRecipient(), $block->getDefaultTo()) ?>" class="input-text">
                                            </div>
                                        </div>
                                         <div class="field text">
                                             <label for="gift-message-<?php /* @escapeNotVerified */ echo $_item->getId() ?>-message" class="label"><span><?php /* @escapeNotVerified */ echo __('Message') ?></span></label>
                                             <div class="control">
                                                <textarea id="gift-message-<?php /* @escapeNotVerified */ echo $_item->getId() ?>-message" class="input-text giftmessage-area" name="giftmessage[quote_address_item][<?php /* @escapeNotVerified */ echo $_item->getId() ?>][message]" title="<?php /* @escapeNotVerified */ echo __('Message') ?>" rows="5" cols="10"><?php /* @escapeNotVerified */ echo $block->getEscaped($block->getMessage($_item)->getMessage()) ?></textarea>
                                             </div>
                                         </div>
                                     </fieldset>
                                 </div>
                             <?php endif; ?>
                         </div>
                     </li>
                 <?php endforeach; ?>
                 </ol>
            </dd>
            <?php endif; ?>
            <dt class="extra-options-container" id="extra-options-container-<?php /* @escapeNotVerified */ echo $block->getEntity()->getId() ?>"></dt>
        </dl>
    </fieldset>
<script type="text/x-magento-init">
    {
        "#allow_gift_options_<?php /* @escapeNotVerified */ echo $block->getEntity()->getId() ?>, #allow_gift_options_for_order_<?php /* @escapeNotVerified */ echo $block->getEntity()->getId() ?>, #allow_gift_options_for_items_<?php /* @escapeNotVerified */ echo $block->getEntity()->getId() ?>": {
            "giftOptions": {}
        }
    }
</script>
    <?php break; ?>
<?php endswitch ?>
<?php if ($_giftMessage): ?>
<script type="text/x-magento-init">
    {
        "#shipping_method_form": {
            "validation": {}
        }
    }
</script>
<?php endif; ?>
